import React from 'react'
import { useAppSelector } from '../app/hooks'

export function useCar() {
	const carList = useAppSelector(state => state.car.carList);
	// 总数量
	const totalCount = carList.reduce((p, n) => {
		return p + n.count
	}, 0)
	// 总价
	const totalPrice = carList.reduce((p, n) => {
		return p + n.count * n.price
	}, 0)

	// 选中总价钱
	const selectTotalPrice = carList.reduce((p, n) => {
		return n.isChecked ?  p + n.count * n.price : p
	}, 0)

	
	return {
		totalCount,
		totalPrice,
		selectTotalPrice
	}
}